layui.config({
    base: path + '/layuiadmin/' //静态资源所在路径
}).extend({
    index: 'lib/index' //主入口模块
}).use(['tree', 'util', 'table'], function () {
    var tree = layui.tree,
        layer = layui.layer,
        user = parent.userObj,
        table = layui.table;

    /**
     * 用户登录日志初始化
     */
    table.render({
        elem: '#loginLogs'
        , url: path + '/main/user/getUserLoginLog.json?userId='+user.userInfo.userId+''
        , height: 300
        , limit: 10
        , loading: true
        , cols: [[
            {field: 'id', width: 80, title: 'ID', sort: true, fixed: 'left', align: 'center'}
            , {field: 'loginAddress', width: 150, title: '登录地点', sort: true, align: 'center'}
            , {field: 'ip', width: 150, title: 'ip地址', sort: true, align: 'center'}
            , {field: 'loginDate',  title: '登录时间', sort: true, align: 'center'}
        ]]
        , page: true
        , done: function (obj) {
            if (obj.data.length == 0) {
                $(".layui-table-main .layui-none").text("暂无登录日志!")
            }
        }
        , text: '对不起，加载出现异常！'
    });

    /**
     * 用户权限树视图初始化
     */
    tree.render({
        elem: '#roles',
        data: user.permissionsTree,
        showCheckbox: false,
        id: 'rolesTree',
        isJump: true,
        accordion: true
    });

    /*填充数据*/
    $(".headImg").attr("src",path+user.userInfo.headImg.filePath).bind("click",function () {
        var url = path + user.userInfo.headImg.filePath;
        var img_infor = "<img src='" +url+ "' id='bigImg' title='点击图片隐藏'/>";
        layer.open({
            type: 1,
            title: false,
            closeBtn: 1,
            area: ['auto', 'auto'],
            shadeClose: true,
            time: 3000,
            content: img_infor,
            success: function(layero, index){
                $("#bigImg").bind("click",function () {
                    layer.close(index)
                })
            }
        });
    });
    $(".userName").text(user.userInfo.userName);
    $(".nickName").text(user.userInfo.nickName);
    $(".email").text(user.userInfo.email==""||user.userInfo.email==null?"未设置":user.userInfo.email);
    $(".phone").text(user.userInfo.phone==""||user.userInfo.phone==null?"未设置":user.userInfo.phone);
    $(".sex").text(user.userInfo.sex);
    $(".age").text(user.userInfo.age);
    $(".roleNames").text(user.userInfo.roleNames);
    $(".birthday").text(user.userInfo.birthday);
    $(".lastLoginTime").text(user.userInfo.lastLoginTime==""||user.userInfo.lastLoginTime==null?"暂未登录过":user.userInfo.lastLoginTime);
    if (user.userInfo.status=="0"){
        $(".layui-form-switch").click();
    }
    $("[name=open]").attr("disabled","disabled");
});